﻿function inputBlur(e) {
  focusFlag = false;
  var eValue = e.value.replace(/^\s*/, "").replace(/\s*$/, "");
  if (eValue == '') {
    e.style.color = "#908f8f";
    e.style.height = "19px";
    e.style.paddingTop = "5px";
    e.style.font = "13px '宋体',arial";
    setTimeout(function() {
    if (tipFlag == true && focusFlag == false) e.value = "";
    }, 125);
  } else { }
}

if (typeof (Event) != "undefined") {
  var aa;
  aa = new AutoComplete(document.sb, "query");
  aa.setSearchServer("http://user.niaoyan.com/search/");
  aa.setSuggestServer("http://www.youdao.com/");
  if (Event.observe) {
    Event.observe(window, "load", function() {
      //if (isIE()) onLoadHandler();
      focusFlag = true;
      if (isIE()) setTimeout(function() { setfocus(); }, 10);
    });
  }
}
var searchBoxUserKeyed = false;
//if (!isIE()) {
//  //onLoadHandler();
//  //setfocus();
//}
function setfocus() {
  var flag = isIE();
  if (flag) {
    //var tagName = document.activeElement.tagName.toUpperCase();
    var id = document.activeElement.id.toUpperCase();
    if (id == "USERNAME" || id == "PASSWORD" || id == "LOGINSELECT" || isFocusChange()) {
      var input = document.getElementById('query');
      input.value = "";
      inputBlur(input);
      return;
    } else {
      nyInputFocus();
    }
  } else {
    nyInputFocus();
  }
}
function nyInputFocus() {
  var input = document.getElementById('query');
  input.focus();
  if (input.value == nyDefault) input.value = "";
  focusFlag = true;
  Event.observe(input, "keydown", autoBlurSearchBox);
}
function isIE() {
  var notMSIE = (navigator && navigator.userAgent.toLowerCase().indexOf("msie") == -1);
  if (!notMSIE) return true;
  return false;
}
function isIE6() {
  return isIE();
}
function isFocusChange() {
  var user = document.getElementById("userName");
  var pass = document.getElementById("password");
  if (user && user.value != "") return true;
  if (pass && pass.value != "") return true;
  return false;
}
function autoBlurSearchBox(e) {
  var navkeys = new Array(32, 33, 34, 35, 36, 37, 38, 39, 40);
  if (!searchBoxUserKeyed) {
    if (navkeys.indexOf(e.keyCode) != -1) {
      var input = document.getElementById('query');
      input.blur();
      inputBlur(input);
    } else {
      var input = document.getElementById('query');
      input.focus();
    }
  }
  searchBoxUserKeyed = true;
}

var tipFlag = true;
function changeProduct(p) {
  var url = getSearchUrl("query", p, "Yabobo.Com");
  window.open(url, "_parent");
  return false;
}

//////////////////////////////////////////////////////////////////////////
// 广告点击模块.

var elements2;
elements2 = document.getElementsByTagName("iframe");
for (var i = 0; i < elements2.length; i++) {
  if (elements2[i].src.indexOf(':/') > -1) {
    if (elements2[i].id != "passport") {
      elements2[i].onfocus = log;
    }    
  }
}

//document.getElementById("query").focus();